package com.doudou.oauth.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * @Author: 傻男人
 * @Date: 2020/5/7 15:42
 * @Version: 1.0
 * @Description:
 */

@Slf4j
@RestController
public class TestSecurityController {

    @GetMapping("/product/{id}")
    public String getProduct(@PathVariable String id) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        return "product id : " + id;
    }

    @GetMapping("/order/{id}")
    public String getOrder(@PathVariable String id, Principal principal) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//        AuthUserDto authUserDto = (AuthUserDto)authentication.getPrincipal();
        return "order id : " + authentication;
    }
}